/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package flight.server;

import flight.model.FlightBufferedTextDataSource;
import flight.model.FlightDataSource;
import flight.service.FlightService;
import java.io.FileNotFoundException;

import java.util.logging.Level;
import java.util.logging.Logger;
import middleware.Naming;

/**
 *
 * @author tam
 */
public class FlightServer {

    public static void main(String args[]) {
        try {
            if (args.length != 2) {
                System.out.println("Parameters format: <threshold> <atmostonce>");
                return;
            }
            System.out.println("threshold = "+ args[0] +", at-most-once = "+args[1].equalsIgnoreCase("1"));
            Float threshold = Float.parseFloat(args[0]);
            int atmost1=Integer.parseInt(args[1]);
            FlightDataSource ds = new FlightBufferedTextDataSource("flights.txt");
            FlightService fs = new FlightServiceImpl(ds);
            Naming naming = new Naming();
            naming.setThreshold(threshold);
            naming.setAtMostOnce(atmost1==1);
            naming.setUpperObject(fs);
            //naming.registerSerializablePrototype()
            naming.setPort(2020);
            System.out.println("Starting server...");
            naming.createRegistry();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FlightServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
